package com.huayun.code.gen.ext;

import com.huayun.code.core.gen.AbstractGenerator;
import com.huayun.code.core.gen.AbstractTableGenerator;
import com.huayun.code.core.utils.ConfigUtils;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Map;

@Component
@DependsOn("configUtils")
public class TableColumnsGen extends AbstractTableGenerator {

    public TableColumnsGen() {

    }

    @Override
    protected Map<String, Object> getDataModel() {
        Map<String, Object> data = super.getDataModel();
        data.put("cols", table.getColumns());
        return data;
    }

    @PostConstruct
    public void init() {
        String basePackage = ConfigUtils.getBasePackage();
        getCfg().put("columnsPackage", basePackage + ".bean.columns");
    }

    @Override
    public String getFileName() {
        return table.getClazzName() + "Columns.java";
    }

    @Override
    public String getType() {
        return AbstractGenerator.MODEL;
    }
}
